package com.blog.study.study2;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Map;

/**
 * 弱引用.
 *
 * @author 张俊强~.
 * @date 2017/11/17-21:54.
 */
public class WeakReferenceDemo {

    public static void main(String[] args) {

        Object obj = new Object();
        WeakReference<Object> wf = new WeakReference<Object>(obj);

        Map m =new HashMap();

        int i = 0;
        for (int j = 0; i < 100000; j++) {

            if(wf.isEnqueued()){
                System.out.println("第"+i+"次已经被标记为垃圾");
            }

            m.put(i, new String("没有释放空间"));
            if (wf.get() == null) {
                System.out.println("第"+i+"次空间已经释放");
            }
            i++;
        }

    }

}
